package enabled

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type Enabled int

const (
	True Enabled = iota + 1
	False
)

func (e Enabled) Code() int32 {
	return int32(e)
}

func (e Enabled) Des() string {
	return enums.BE(e).Des
}

func (e Enabled) Enum() string {
	return enums.BE(e).Enum
}

func (e Enabled) Val() int {
	return int(e)
}

func (e *Enabled) UnmarshalJSON(value []byte) error {
	*e = Enabled(enums.UnmarshalEnum(value))
	return nil
}

func (e Enabled) MarshalJSON() ([]byte, error) {
	switch e {
	case True:
		return enums.JsonObj(int(e), "True", "启用")
	case False:
		return enums.JsonObj(int(e), "False", "未启用")
	}
	return []byte(strconv.Itoa(int(e))), nil
}

func SelectOptions() []enums.SelectOptions {
	return enums.ToSelectOptions([]any{True, False})
}
